package kr.hyunist.androidcomplete01saeildamil.ch19;

import kr.hyunist.androidcomplete01saeildamil.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class ThreadEx01 extends Activity {
	int mMainValue = 0;
	int mBackValue = 0;
	TextView mMainText;
	TextView mBackText;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.threadtest01);
		
		mMainText = (TextView) findViewById(R.id.threadtesttv1);
		mBackText = (TextView) findViewById(R.id.threadtesttv2);
		
		BackThread thread = new BackThread();
		thread.setDaemon(true);
		thread.start();
	}
	
	class BackThread extends Thread {

		@Override
		public void run() {
			while(true){
				mBackValue++;
				//mBackText.setText("BackValue : " + mBackValue);
				try {
					Thread.sleep(1000);
				} catch(InterruptedException e) {
					e.getStackTrace();
				}
			}
		}
		
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.threadtestbtn:
			mMainValue++;
			mMainText.setText("MainValue : " + mMainValue);
			mBackText.setText("BackValue : " + mBackValue);
			break;
		}
	}
}
